package com.linkin.homepage.ui.home.exam;

import androidx.annotation.NonNull;

import com.linkin.homepage.app.PreloadApi;
import com.linkin.homepage.base.util.Predictor;
import com.linkin.homepage.bean.ExamDataBean;

import java.util.List;

import io.reactivex.disposables.CompositeDisposable;

public class ExamPresenter implements ExamContract.Presenter {

    @NonNull
    private CompositeDisposable mCompositeDisposable;

    private String mExamId;
    private ExamContract.View mNewsView;

    ExamPresenter(ExamContract.View newsView, String examId) {
        mNewsView = newsView;
        mExamId = examId;
        mNewsView.setPresenter(this);
        mCompositeDisposable = new CompositeDisposable();
    }

    @Override
    public void subscribe() {
        subscribe(false);
    }

    @Override
    public void subscribe(boolean isGesture) {
        mCompositeDisposable.clear();
        getExamInfo(mExamId);
    }

    @Override
    public void unsubscribe() {
        mCompositeDisposable.clear();
    }

    @Override
    public void getExamInfo(String mExamId) {
        //TODO 网络请求，获取数据
        //模拟数据处理
        List<ExamDataBean> examList = PreloadApi.getExamData();
        if (examList != null && Predictor.isNotEmpty(examList)) {
            for (ExamDataBean examDataBean : examList) {
                if (mExamId.equals(examDataBean.getExamId())) {
                    mNewsView.showNewsHome(examDataBean);
                    break;
                }
            }
        }
    }

}

